//
//  SISSTextShowViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/9/1.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSTextShowViewController.h"
#import "SISSBaseView.h"
#import "AttributedLabel.h"

@interface SISSTextShowViewController ()

/* titleLabel */
@property (weak, nonatomic) UILabel *titleLabel;

/* label */
@property (weak, nonatomic) AttributedLabel *label;

@end

@implementation SISSTextShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}



#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    [self.view addSubview:scrollView];
    
    // 1. 添加一个视图，四周和 scrollView 一致
    SISSBaseView *containerView = [[SISSBaseView alloc] init];
    [scrollView addSubview:containerView];
    
    // 2. 自动布局
    WeakSelf
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        if (@available(iOS 11.0, *)) {
            make.top.equalTo(weakSelf.mas_topLayoutGuideBottom);
            make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.top.equalTo(weakSelf.view);
            make.bottom.equalTo(weakSelf.view);
        }
    }];
    [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(scrollView);
        make.width.mas_equalTo(SCREEN_WIDTH);
        // 通过宽高设置 contentSize
        //        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT * 1.5));
    }];
    
    UILabel *titleLabel = [UILabel yyr_labelWithText:self.titleStr fontSize:16 textColor:MAIN_TEXT_COLOR];
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.hidden = !self.titleStr;
    [containerView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    AttributedLabel *label = [AttributedLabel labelWithText:self.textStr fontSize:16 textColor:MAIN_TEXT_COLOR];

    for (NSInteger i = 0; i < self.boldTextArr.count; i++) {
        [label setStyleName:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16] ofRange:[self.textStr rangeOfString:self.boldTextArr[i]]];
        [label setFontColor:MAIN_TEXT_COLOR ofRange:[self.textStr rangeOfString:self.boldTextArr[i]]];
    }
    [label setLineSpace:10 ofRange:NSMakeRange(0, self.textStr.length)];
    [containerView addSubview:label];
    self.label = label;
    
    CGFloat margin = 8.0;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(containerView).offset(2 * margin);
        make.right.equalTo(containerView).offset(-2 * margin);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(2 * margin);
        make.left.equalTo(containerView).offset(2 * margin);
        make.right.bottom.equalTo(containerView).offset(-2 * margin);
    }];
}

@end
